package com.my.study.init.serverInit;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public class PaymentFactory {

    private static Map<Integer,BasePaymentService> beanMap = new ConcurrentHashMap<>();

    public static BasePaymentService crate(int code){
        return beanMap.get(code);
    }

    public static void setBeanMap(Map<String, BasePaymentService> beansOfType){
        if(beansOfType == null || beansOfType.isEmpty()){
            return;
        }
        log.info("PaymentFactory start setBeanMap");
        for (Map.Entry<String, BasePaymentService> entry : beansOfType.entrySet()) {
            log.info("监听的类:{}",entry.getValue().paymentListener.getClass().getName());
            // 可以在此将自己的监听设置进去entry.getValue().setListener(new MyPaymentListener());
            beanMap.put(entry.getValue().getPayTypeEnum().code,entry.getValue());
        }
        log.info("PaymentFactory end setBeanMap");
    }
}
